package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallCouponUser;
import com.tencreat.service.mall.IMallCouponUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 优惠券用户使用Controller
 *
 * @author tencreat
 * @date 2021-08-15
 */
@Api(tags="优惠券用户使用api")
@RestController
@RequestMapping("/mall/couponUser")
public class AdminMallCouponUserController extends BaseController {
    @Autowired
    private IMallCouponUserService mallCouponUserService;

    /**
     * 查询优惠券用户使用列表
     */
    @ApiOperation(value="查询优惠券用户使用列表")
    @PreAuthorize("@ss.hasPermi('mall:couponUser:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallCouponUser>> list(@RequestBody  MallCouponUser mallCouponUser) {
        QueryWrapper<MallCouponUser> wrapper = Wrappers.query(mallCouponUser);
        Page<MallCouponUser> page =  new Page<>(mallCouponUser.getPageNum(), mallCouponUser.getPageSize());
        return HttpResult.ok(mallCouponUserService.page(page, wrapper));
    }

    /**
     * 导出优惠券用户使用列表
     */
    @ApiOperation(value="导出优惠券用户使用列表")
    @PreAuthorize("@ss.hasPermi('mall:couponUser:export')")
    @Log(title = "优惠券用户使用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallCouponUser mallCouponUser) {
        List<MallCouponUser> list = mallCouponUserService.selectMallCouponUserList(mallCouponUser);
        ExcelUtil<MallCouponUser> util = new ExcelUtil<MallCouponUser>(MallCouponUser.class);
        return util.exportExcel(list, "couponUser");
    }

    /**
     * 获取优惠券用户使用详细信息
     */
    @ApiOperation(value="获取优惠券用户使用详细信息")
    @PreAuthorize("@ss.hasPermi('mall:couponUser:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallCouponUser> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallCouponUserService.selectMallCouponUserById(id));
    }

    /**
     * 新增优惠券用户使用
     */
    @ApiOperation(value="新增优惠券用户使用")
    @PreAuthorize("@ss.hasPermi('mall:couponUser:add')")
    @Log(title = "优惠券用户使用", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallCouponUser mallCouponUser) {
        return to(mallCouponUserService.insertMallCouponUser(mallCouponUser));
    }

    /**
     * 修改优惠券用户使用
     */
    @ApiOperation(value="修改优惠券用户使用")
    @PreAuthorize("@ss.hasPermi('mall:couponUser:edit')")
    @Log(title = "优惠券用户使用", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallCouponUser mallCouponUser) {
        return to(mallCouponUserService.updateMallCouponUser(mallCouponUser));
    }

    /**
     * 删除优惠券用户使用
     */
    @ApiOperation(value="删除优惠券用户使用")
    @PreAuthorize("@ss.hasPermi('mall:couponUser:remove')")
    @Log(title = "优惠券用户使用", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallCouponUserService.deleteMallCouponUserByIds(ids));
    }
}
